              package com.java.diagnostics.visualizer.displayer.plot;
              
              import com.java.diagnostics.visualizer.data.TupleData;
              import com.java.diagnostics.visualizer.properties.OutputProperties;
              
              public class YPositionConverter extends PositionConverter
              {
                protected int plotHeight;
                protected int plotBottom;
                protected static final int MIN_TICKS = 10;
                protected static final double Y_PADDING_PROPORTION = 0.1D;
                protected double yPadding;
                protected boolean padPlots;
                private boolean forceYAxisToStartAtZero = false;
              
                public YPositionConverter(boolean padPlots, boolean forceZero) {
                  this.padPlots = padPlots;
                  this.forceYAxisToStartAtZero = forceZero;
                }
              
                public int convertToPosition(double num) {
                  double offset = this.lowerLimit - num;
                  double unrounded;
/*     *///          double unrounded;
                  if (this.delta > 0.0D) {
                    unrounded = this.plotBottom + offset * (this.plotHeight / this.delta);
                  }
                  else
                  {
                    unrounded = this.plotBottom - this.plotHeight / 2;
                  }
              
                  return (int)Math.round(unrounded);
                }
              
                public double convertToValue(int position) {
                  double offset = (position - this.plotBottom) / (this.plotHeight / this.delta);
              
                  return this.lowerLimit - offset;
                }
              
                protected void calculateDeltas()
                {
                  double topPadding = 0.0D;
                  this.delta = (this.max - this.min);
                  this.lowerLimit = this.min;
              
                  if (this.padPlots) {
                    double y = this.min;
              
                    topPadding = this.delta * 0.1D;
                    if ((y > 0.0D) && (this.delta != 0.0D) && (y / this.delta < 0.1D)) {
                      this.yPadding = y;
                    }
                    else if (this.delta == 0.0D)
                      this.yPadding = topPadding;
                  }
                  else
                  {
                    this.yPadding = 0.0D;
                  }
              
                  this.delta = (this.delta + this.yPadding + topPadding);
                  this.lowerLimit -= this.yPadding;
                }
              
                public void updateLimits(int plotBottom, int plotTop)
                {
                  this.plotBottom = plotBottom;
                  this.plotHeight = Math.abs(plotTop - plotBottom);
                }
              
                public void updateLabelsAndAxes(OutputProperties properties, TupleData data)
                {
                  if (data.isEmpty()) {
                    return;
                  }
              
                  if (this.forceYAxisToStartAtZero) {
                    this.min = 0.0D;
                  } else {
                    double mindata = data.getMinY(properties.getYUnits(data));
                    if (mindata < this.min) {
                      this.min = mindata;
                    }
              
                  }
              
                  double maxdata = data.getMaxY(properties.getYUnits(data));
                  if (maxdata > this.max) {
                    this.max = maxdata;
                  }
              
                  calculateDeltas();
                }
              }

